<template>
  <div class="barebones zh">
    <div class="ebates-login">
      <div class="header">
        <ul class="main-nav">
          <li class="nav-item"><a href="/">首页</a></li>
          <li class="nav-item"><a href="/">帮助中心</a></li>
        </ul>
      </div>
      <div id="layout" class="ui-helper-clearfix">
        <div class="icon-sign-signup-benefits-5-dollars"></div>
        <div id="login-global-content" class="login-register-page">

          <div class="login-global on">
            <div class="tabs clearfix on">
              <router-link class="tab-register" to="register">注册</router-link>
              <a href="javascript: void 0" class="tab-login active">登录</a>
            </div>

            <!-- login box start -->
            <div class="login-box on">

              <h3></h3>
              <div class="messages"></div>

              <!--&lt;!&ndash; login form start &ndash;&gt;-->
              <!--<form id="login-form" class="form" method="post" action="/users/login" novalidate="novalidate">-->
                <!--<input type="hidden" name="csrf" value="7565a09626df1e6c">-->
                <!--<input type="hidden" name="return" value="/in-store-cash-back">-->
                <!--<div class="group group-email">-->
                  <!--<input id="email" name="email" class="text-input blurred" type="text" placeholder="输入邮箱/手机号">-->
                <!--</div>-->
                <!--<div class="group group-password">-->
                  <!--<input id="password" name="password" type="password" class="text-input blurred" placeholder="输入密码">-->
                <!--</div>-->
                <!--<div class="group group-captcha">-->
                  <!--<input id="captcha" name="captcha" autocomplete="off" type="text" class="text-input blurred" placeholder="输入验证码" maxlength="6">-->
                <!--</div>-->
                <!--<div class="group group-btn">-->
                  <!--<input type="button" value="登录" class="submit">-->
                <!--</div>-->
                <!--<div class="group-text">-->
                  <!--<span class="r"><a class="link-login-phone" href="javascript:;">手机号快速登录</a></span>-->
                  <!--<a href="/">忘记密码？</a>-->
                <!--</div>-->
              <!--</form>-->
              <!--&lt;!&ndash; login form end &ndash;&gt;-->

              <!-- login phone form start -->
              <form id="login-phone-form" class="form on" method="post" action="/users/login">
                <input type="hidden" name="return" value="/in-store-cash-back">
                <input type="hidden" name="csrf" value="7565a09626df1e6c">
                <input type="hidden" name="login-phone" value="true">
                <div class="group group-phone">
                  <div class="l"><input id="phone" name="phone" class="text-input blurred" type="text" v-model="mob" maxlength="11" placeholder="输入手机号"></div>
                  <div class="r"><input type="button" value="发送动态码" class="button btn-send-phone-code"></div>
                </div>
                <div class="group">
                  <input id="password" name="password" type="text" class="text-input blurred" maxlength="6" placeholder="输入动态码" v-model="pwd">
                </div>
                <div class="group group-captcha">
                  <input id="captcha" name="captcha" autocomplete="off" type="text" class="text-input blurred" placeholder="输入验证码" maxlength="6">
                </div>
                <div class="group group-btn">
                  <input type="button" value="登录" class="submit" @click="doLogin">
                </div>
                <div class="group-text">
                  <span class="r"><a class="link-login-email" href="javascript:;">使用邮箱登录</a></span>
                  <a href="/">忘记密码？</a>
                </div>
              </form>
              <!-- login phone form end -->

              <div class="society">
                <a class="qq-connect" rel="nofollow" href="/"><i class="icon-sprites icon-l-qq"></i> QQ登录</a>
                <a class="weibo-connect" rel="nofollow" href="/"><i class="icon-sprites icon-l-weibo"></i> 微博登录</a>
                <a class="alipay-express" rel="nofollow" href="/"><i class="icon-sprites icon-l-alipay"></i> 支付宝</a>
              </div>

              <div class="login-link">
                <a href="javascript:;">还没有帐号？去注册 &gt;&gt;</a>
              </div>

            </div>
            <!-- login box end -->

          </div>

        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import '../../pc.page.css'
  import {login, sendSMS} from './login'

  export default {
    data() {
      return {
        mob: '',
        pwd: ''
      }
    },
    methods: {
      doLogin() {
        let message
        if (this.mob.length === 0) {
          message = '请输入手机号'
        } else if (!/^1[34578]\d{9}$/.test(this.mob)) {
          message = '请输入正确的手机号'
        } else if (this.pwd.length === 0) {
          message = '请输入动态码'
        }

        if (message) {
          alert(message)
          return
        }
        login(this.mob, this.pwd)
          .then(x => {
            this.$router.replace(this.$route.query.redirect || '/')
          })
      },
      sendMes() {
        sendSMS(this.mob)
          .then(success => {
            if (success) {
              // TODO: 发送验证码成功
            }
          })
      }
    }
  }
</script>

<style>
  .ebates-login .main-nav {
    float: left;
  }
  .nav-item>a {
    font-size: 14px!important;
    font-weight: bold;
  }
</style>
